package com.ruoyi.system.outto.goods.impl;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttrTemplateMapper;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.gameAttr.service.IGameAttributeService;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.interAttr.mapper.InterAttrMapper;
import com.ruoyi.system.model.domain.ArtRec;
import com.ruoyi.system.model.domain.GameAttribute;
import com.ruoyi.system.model.domain.GoodsInfoImg;
import com.ruoyi.system.model.domain.SalePartner;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.core.OutUrlConstant;
import com.ruoyi.system.outto.core.constant.GameTypeConstant;
import com.ruoyi.system.outto.goods.NEWCRAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/8/16 22:58
 */
@Slf4j
@Service
public class NEWCRApiImpl implements NEWCRAPI {

    @Resource
    private IGameAttributeService gameAttributeService;
    @Resource
    InterAttrMapper interAttrMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private ArtRecMapper artRecMapper;
    @Resource
    private GameAttrTemplateMapper gameAttrTemplateMapper;


    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> resultMap = new HashMap<>();

        Map<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner, "1");
        log.info("超人添加接口请求参数={}", JSONObject.toJSONString(params));
        String result = HttpRequest.post("http://crkc.dtwlkj.cn/api/add").body(JSONObject.toJSONString(params)).execute().body();
        log.info("超人添加接口返回参数={}", result);
        JSONObject resultJson = JSONObject.parseObject(result);
        String data = resultJson.getString("data");
        if (!"200".equals(resultJson.getString("code"))) {
            resultMap.put("code", 500);
        } else {
            resultMap.put("code", 200);
            resultMap.put("outId", goodsInfoAndAttrValueDto.getId());
        }
        resultMap.put("req", JSONObject.toJSONString(params));
        resultMap.put("res", result);
        resultMap.put("msg", resultJson.getString("data"));

        return AjaxResult.success(resultMap);
    }

    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> resultMap = new HashMap<>();

        Map<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner, "2");
        log.info("超人编辑接口请求参数={}", JSONObject.toJSONString(params));
        String result = HttpRequest.post("http://crkc.dtwlkj.cn/api/add").body(JSONObject.toJSONString(params)).execute().body();
        log.info("超人编辑接口返回参数={}", result);


        JSONObject resultJson = JSONObject.parseObject(result);
        if (!"200".equals(resultJson.getString("code"))) {
            resultMap.put("code", 500);
        } else {
            resultMap.put("code", 200);
        }
        resultMap.put("req", JSONObject.toJSONString(params));
        resultMap.put("res", result);
        resultMap.put("msg", resultJson.getString("data"));

        return AjaxResult.success(resultMap);
    }

    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner, "4");
        log.info("超人删除接口请求参数={}", JSONObject.toJSONString(params));
        String result = HttpRequest.post("http://crkc.dtwlkj.cn/api/add").body(JSONObject.toJSONString(params)).execute().body();
        log.info("超人删除接口返回参数={}", result);


        JSONObject resultJson = JSONObject.parseObject(result);
        if(Objects.nonNull(resultJson)) {
            if (!"200".equals(resultJson.getString("code"))) {
                resultMap.put("code", 500);
            } else {
                resultMap.put("code", 200);
            }
        }else{
            resultMap.put("code", 500);
        }
        resultMap.put("req", JSONObject.toJSONString(params));
        resultMap.put("res", result);
        resultMap.put("msg", resultJson.getString("data"));

        return AjaxResult.success(resultMap);
    }

    private Map<String, Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner sa, String type) {

        Map<String, Object> params = new TreeMap<>();
        params.put("sign", sa.getSaleKey());
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(sa.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        if(CollectionUtils.isNotEmpty(artRecs)) {
            params.put("cid", artRecs.get(0).getOutid());
        }else {
            params.put("cid", goodsInfoAndAttrValueDto.getId());
        }
        params.put("type", type);
        params.put("account", goodsInfoAndAttrValueDto.getAccountNumber());
        if (Arrays.asList(mobleGames).contains(goodsInfoAndAttrValueDto.getGameName())) {
            String s = gameCover(goodsInfoAndAttrValueDto.getGameName(), goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName());
            if (Objects.isNull(s)) {
                throw new GlobalException("区服匹配失败，当前游戏:" + goodsInfoAndAttrValueDto.getGameName() + "，区服" + goodsInfoAndAttrValueDto.getSystemName() + goodsInfoAndAttrValueDto.getCarrierName());
            }
            params.put("gameSystemId", s);
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("英雄联盟")) {
            String area = getArea(sa, "107");
            JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(area).getString("data"));
            for (Object o : jsonArray) {
                JSONArray jsonArray1 = JSONArray.parseArray(JSONObject.parseObject(o.toString()).getString("areaList"));
                for (Object p : jsonArray1) {
                    if (goodsInfoAndAttrValueDto.getServerName().contains(JSONObject.parseObject(p.toString()).getString("gameAreaName"))) {
                        params.put("gameSystemId", JSONObject.parseObject(p.toString()).getString("gameSystemId"));
                        params.put("gameAreaId", JSONObject.parseObject(p.toString()).getString("gameAreaId"));
                    }
                }
            }
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("穿越火线")) {
            params.put("gameSystemId", "1041");
            if (goodsInfoAndAttrValueDto.getGroupName().contains("东部")) {
                params.put("gameAreaId", "6440");
            } else if (goodsInfoAndAttrValueDto.getGroupName().contains("西部")) {
                params.put("gameAreaId", "6441");
            } else if (goodsInfoAndAttrValueDto.getGroupName().contains("南部")) {
                params.put("gameAreaId", "6442");
            } else {
                params.put("gameAreaId", "6443");
            }
        } else if (goodsInfoAndAttrValueDto.getGameName().contains("地下城与勇士")) {
            String groupName = goodsInfoAndAttrValueDto.getGroupName();
            if (Objects.equals(groupName, "跨1")) {
                params.put("gameSystemId", "1023");
            } else if (Objects.equals(groupName, "跨2")) {
                params.put("gameSystemId", "1024");
            } else if (Objects.equals(groupName, "跨3A")) {
                params.put("gameSystemId", "1025");
            } else if (Objects.equals(groupName, "跨3B")) {
                params.put("gameSystemId", "1026");
            } else if (Objects.equals(groupName, "跨4")) {
                params.put("gameSystemId", "1027");
            } else if (Objects.equals(groupName, "跨5")) {
                params.put("gameSystemId", "1028");
            } else if (Objects.equals(groupName, "跨6")) {
                params.put("gameSystemId", "1029");
            } else if (Objects.equals(groupName, "跨7")) {
                params.put("gameSystemId", "1030");
            } else if (Objects.equals(groupName, "跨8")) {
                params.put("gameSystemId", "1032");
            }
            params.put("gameId", "109");
        }else if (goodsInfoAndAttrValueDto.getGameName().contains("原神")) {
            params.put("gameId", "114");
            if(goodsInfoAndAttrValueDto.getCarrierName().equals("游戏官方")){
                params.put("gameSystemId", "1039");
            }else{
                params.put("gameSystemId", "1040");
            }
        }

        String s = coverGameId(goodsInfoAndAttrValueDto.getGameName());
        if (Objects.isNull(s)) {
            throw new GlobalException("游戏匹配失败，当前游戏:" + goodsInfoAndAttrValueDto.getGameName());
        }
        params.put("gameId", s);
        params.put("encryptedPhone", "111");
        GameAttribute gameAttribute = null;
        if (!Objects.equals("英雄联盟", goodsInfoAndAttrValueDto.getGameName())) {
            if (Objects.equals("王者荣耀", goodsInfoAndAttrValueDto.getGameName())) {
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
                if (gameAttribute.getFieldName().contains("可二次实名")) {
                    params.put("autonymState", 2);
                } else if (gameAttribute.getFieldName().contains("不可二次实名")) {
                    params.put("autonymState", 4);
                } else if (gameAttribute.getFieldName().contains("已删实名")) {
                    params.put("autonymState", 3);
                } else {
                    params.put("autonymState", 0);
                }
            } else if (Objects.equals("和平精英", goodsInfoAndAttrValueDto.getGameName())) {
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
                if (gameAttribute.getFieldName().contains("可二次实名")) {
                    params.put("autonymState", 2);
                } else if (gameAttribute.getFieldName().contains("不可二次实名")) {
                    params.put("autonymState", 4);
                } else if (gameAttribute.getFieldName().contains("已删实名")) {
                    params.put("autonymState", 3);
                } else {
                    params.put("autonymState", 0);
                }
            } else if (Objects.equals("枪战王者", goodsInfoAndAttrValueDto.getGameName())) {
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
                if (gameAttribute.getFieldName().contains("有修改人脸机会")) {
                    params.put("autonymState", 2);
                } else if (gameAttribute.getFieldName().contains("无修改人脸机会")) {
                    params.put("autonymState", 4);
                } else if (gameAttribute.getFieldName().contains("已删人脸实名可随时认证")) {
                    params.put("autonymState", 3);
                } else {
                    params.put("autonymState", 0);
                }
            } else if (Objects.equals("QQ飞车手游", goodsInfoAndAttrValueDto.getGameName())) {
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
                if (gameAttribute.getFieldName().contains("可实名")) {
                    params.put("autonymState", 2);
                } else if (gameAttribute.getFieldName().contains("包人脸")) {
                    params.put("autonymState", 4);
                } else {
                    params.put("autonymState", 3);
                }
            } else if (Objects.equals("火影忍者", goodsInfoAndAttrValueDto.getGameName())) {
                if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF10())) {
                    gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
                }
            } else if (Objects.equals("原神", goodsInfoAndAttrValueDto.getGameName())) {
                if (StringUtils.isEmpty(goodsInfoAndAttrValueDto.getF20())) {
                    throw new GlobalException("实名不能为空");
                }
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
                if (gameAttribute.getFieldName().contains("有修改人脸机会")) {
                    params.put("autonymState", 2);
                } else if (gameAttribute.getFieldName().contains("无修改人脸机会")) {
                    params.put("autonymState", 4);
                } else if (gameAttribute.getFieldName().contains("已删人脸实名可随时认证")) {
                    params.put("autonymState", 3);
                } else if (gameAttribute.getFieldName().contains("游戏已实名")) {
                    params.put("autonymState", 6);
                } else if (gameAttribute.getFieldName().contains("游戏未实名")) {
                    params.put("autonymState", 5);
                }
            } else if (Objects.equals("穿越火线", goodsInfoAndAttrValueDto.getGameName())) {
                if (StringUtils.isEmpty(goodsInfoAndAttrValueDto.getF3())) {
                    throw new GlobalException("实名不能为空");
                }
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
                if (gameAttribute.getFieldName().contains("有修改机会")) {
                    params.put("autonymState", 2);
                } else if (gameAttribute.getFieldName().contains("无修改机会")) {
                    params.put("autonymState", 4);
                } else if (gameAttribute.getFieldName().contains("已删实名")) {
                    params.put("autonymState", 3);
                }
            } else if (Objects.equals("地下城与勇士", goodsInfoAndAttrValueDto.getGameName())) {
                if (StringUtils.isEmpty(goodsInfoAndAttrValueDto.getF1())) {
                    throw new GlobalException("实名不能为空");
                }
                gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
                if (gameAttribute.getFieldName().contains("可实名")) {
                    params.put("autonymState", 2);
                } else {
                    params.put("autonymState", 4);
                }
            }
        } else {
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
            if (gameAttribute.getFieldName().contains("有修改人脸机会")) {
                params.put("autonymState", 2);
            } else if (gameAttribute.getFieldName().contains("无修改人脸机会")) {
                params.put("autonymState", 4);
            } else {
                params.put("autonymState", 3);
            }
        }
        params.put("title", goodsInfoAndAttrValueDto.getDes().length()>2000?goodsInfoAndAttrValueDto.getDes().substring(0,1999):goodsInfoAndAttrValueDto.getDes());
//        String sr2[] = {"王者荣耀","英雄联盟"};
        if (goodsInfoAndAttrValueDto.getGameName().contains("王者荣耀")) {
            params.put("standby2", goodsInfoAndAttrValueDto.getF7() == null || goodsInfoAndAttrValueDto.getF7().equals("") ? 0 : goodsInfoAndAttrValueDto.getF7());
            params.put("standby3", goodsInfoAndAttrValueDto.getF8() == null || goodsInfoAndAttrValueDto.getF8().equals("") ? 0 : goodsInfoAndAttrValueDto.getF8());
            params.put("standby6", goodsInfoAndAttrValueDto.getF13() == null || goodsInfoAndAttrValueDto.getF13().equals("") ? 0 : goodsInfoAndAttrValueDto.getF13());
            params.put("standby7", goodsInfoAndAttrValueDto.getF4() == null || goodsInfoAndAttrValueDto.getF4().equals("") ? 0 : goodsInfoAndAttrValueDto.getF4());
        }
        if (goodsInfoAndAttrValueDto.getGameName().contains("英雄联盟")) {
            params.put("standby2", goodsInfoAndAttrValueDto.getF3() == null || goodsInfoAndAttrValueDto.getF3().equals("") ? 0 : goodsInfoAndAttrValueDto.getF3());
            params.put("standby3", goodsInfoAndAttrValueDto.getF4() == null || goodsInfoAndAttrValueDto.getF4().equals("") ? 0 : goodsInfoAndAttrValueDto.getF4());
        }
        if (goodsInfoAndAttrValueDto.getGameName().contains("原神")) {
            params.put("standby2", goodsInfoAndAttrValueDto.getF8() == null || goodsInfoAndAttrValueDto.getF8().equals("") ? 0 : goodsInfoAndAttrValueDto.getF8());
            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF11())) {
                String[] strings = goodsInfoAndAttrValueDto.getF11().split(",");
                params.put("standby3", strings.length);
            }
            if (StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF18())) {
                String[] strings = goodsInfoAndAttrValueDto.getF18().split(",");
                params.put("standby6", strings.length);
            }
        }
        String sr2hp[] = {"和平精英"};
        if (Arrays.asList(sr2hp).contains(type)) {
            params.put("standby2", goodsInfoAndAttrValueDto.getF8() == null || goodsInfoAndAttrValueDto.getF8().equals("") ? 0 : goodsInfoAndAttrValueDto.getF8());
            params.put("standby3", goodsInfoAndAttrValueDto.getF9() == null || goodsInfoAndAttrValueDto.getF9().equals("") ? 0 : goodsInfoAndAttrValueDto.getF9());
            params.put("standby6", goodsInfoAndAttrValueDto.getF7() == null || goodsInfoAndAttrValueDto.getF7().equals("") ? 0 : goodsInfoAndAttrValueDto.getF7());
            params.put("standby7", goodsInfoAndAttrValueDto.getF11() == null || goodsInfoAndAttrValueDto.getF11().equals("") ? 0 : goodsInfoAndAttrValueDto.getF11());
        }
        params.put("price", goodsInfoAndAttrValueDto.getPrice().stripTrailingZeros().toPlainString());

        GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
        goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
        goodsInfoImg.setType(Constants.STR_1);
        List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
        String imgUrls = infoImgs.stream().map(info -> info.getImgUrl()).collect(Collectors.toList()).stream().collect(Collectors.joining(","));
        List<String> list = new ArrayList<>();
        if (StringUtils.isNotEmpty(imgUrls)) {
            list = Arrays.asList(imgUrls.split(","));
        }
        String imgs = "";
        if (!CollectionUtils.isEmpty(list)) {
            imgs = list.stream().collect(Collectors.joining(","));
        }
        if (StringUtils.isEmpty(imgs)) {
            imgs = sa.getTwoOther();
        }
        params.put("imgList", imgs);
        params.put("password", "");
        String camid = "";
        if (goodsInfoAndAttrValueDto.getGameName().contains("和平精英")) {
            camid = goodsInfoAndAttrValueDto.getF13();
        }
        if (goodsInfoAndAttrValueDto.getGameName().contains("王者荣耀")) {
            camid = goodsInfoAndAttrValueDto.getF17();
        }
        params.put("campId", "".equals(camid) || camid == null ? "123" : camid);
        params.put("remark", "");
        return params;
    }

    private static String mobleGames[] = {"王者荣耀", "和平精英", "枪战王者", "QQ飞车手游", "火影忍者"};

    private String gameCover(String game, String regional) {

        if ("王者荣耀".contains(game)) {
            if (Objects.equals("安卓QQ", regional)) {
                return "1007";
            } else if (Objects.equals("安卓微信", regional)) {
                return "1008";
            } else if (Objects.equals("苹果微信", regional)) {
                return "1010";
            } else if (Objects.equals("苹果QQ", regional)) {
                return "1009";
            } else {
                return null;
            }
        }else if ("和平精英".contains(game)) {
            if (Objects.equals("安卓QQ", regional)) {
                return "1011";
            } else if (Objects.equals("安卓微信", regional)) {
                return "1012";
            } else if (Objects.equals("苹果微信", regional)) {
                return "1014";
            } else if (Objects.equals("苹果QQ", regional)) {
                return "1013";
            } else {
                return null;
            }
        }else if ("枪战王者".contains(game)) {
            if (Objects.equals("安卓QQ", regional)) {
                return "1019";
            } else if (Objects.equals("安卓微信", regional)) {
                return "1020";
            } else if (Objects.equals("苹果微信", regional)) {
                return "1022";
            } else if (Objects.equals("苹果QQ", regional)) {
                return "1021";
            } else {
                return null;
            }
        }else if ("火影忍者".contains(game)) {
            if (Objects.equals("安卓QQ", regional)) {
                return "1042";
            } else if (Objects.equals("安卓微信", regional)) {
                return "1043";
            } else if (Objects.equals("苹果微信", regional)) {
                return "1045";
            } else if (Objects.equals("苹果QQ", regional)) {
                return "1044";
            } else {
                return null;
            }
        }
        return null;
    }


    private Map<String, String> coverPc(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, String regional, String key) {

        Map<String, String> params = new HashMap<>();
        params.put("sign", key);
        params.put("gameId", "107");

        if (Objects.equals("穿越火线", goodsInfoAndAttrValueDto.getGameName())) {
            params.put("gameId", "110");
        }

        if (Objects.equals(GameTypeConstant.LOL, goodsInfoAndAttrValueDto.getGameName()) || Objects.equals("穿越火线", goodsInfoAndAttrValueDto.getGameName())) {
            String result = HttpUtils.doPostForm(OutUrlConstant.CRURLR, params, null);
            JSONObject resultJson = JSONObject.parseObject(result);
            if (resultJson.getBoolean("success")) {
                Map<String, String> resultMap = new HashMap<>();
                JSONArray dataList = JSONArray.parseArray(resultJson.getString("data"));
                for (Object datum : dataList) {
                    JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(datum));
                    JSONArray areaList = JSONArray.parseArray(data.getString("areaList"));
                    for (Object area : areaList) {
                        JSONObject areaJson = JSONObject.parseObject(JSONObject.toJSONString(area));
                        log.info("区名称={}", areaJson.getString("gameAreaName"));

//                        if (game.equals("穿越火线")) {
//                            if (Objects.equals(regional,"东部大区")){
//                                regional = "东部战区";
//                            }
//                            if (Objects.equals(regional,"西部大区")){
//                                regional = "西部战区";
//                            }
//                            if (Objects.equals(regional,"南部大区")){
//                                regional = "南部战区";
//                            }
//                            if (Objects.equals(regional,"北部大区")){
//                                regional = "北部战区";
//                            }
//                        }

                        if (Objects.equals(regional, areaJson.getString("gameAreaName"))) {
                            resultMap.put("gameAreaId", areaJson.getString("gameAreaId"));
                            resultMap.put("gameSystemId", data.getString("gameSystemId"));
                            return resultMap;
                        }
                    }
                }
            }
        } else if (Objects.equals(GameTypeConstant.DNF, goodsInfoAndAttrValueDto.getGameName())) {
            params.put("gameId", "109");
        } else if (Objects.equals(GameTypeConstant.QQCAR, goodsInfoAndAttrValueDto.getGameName())) {
            params.put("gameId", "109");
        } else if (Objects.equals(GameTypeConstant.YS, goodsInfoAndAttrValueDto.getGameName())) {
            params.put("gameId", "114");
        } else if (Objects.equals(GameTypeConstant.YJWJ, goodsInfoAndAttrValueDto.getGameName())) {
            params.put("gameId", "115");
        }
        String result = HttpUtils.doPostForm(OutUrlConstant.CRURLR, params, null);
        JSONObject resultJson = JSONObject.parseObject(result);
        if (resultJson.getBoolean("success")) {
            Map<String, String> resultMap = new HashMap<>();
            JSONArray dataList = JSONArray.parseArray(resultJson.getString("data"));
            for (Object datum : dataList) {

                if (Objects.equals(GameTypeConstant.YJWJ, goodsInfoAndAttrValueDto.getGameName())) {

                    if (Objects.equals(regional, "网易")) {
                        regional = "网易端";
                    }
                    if (Objects.equals(regional, "Steam")) {
                        regional = "Steam端";
                    }
                }
                if (Objects.equals(GameTypeConstant.YS, goodsInfoAndAttrValueDto.getGameName())) {

                    if (Objects.equals(goodsInfoAndAttrValueDto.getCarrierName(), "哔哩哔哩")) {
                        regional = "B服";
                    }
                    if (Objects.equals(goodsInfoAndAttrValueDto.getCarrierName(), "游戏官方")) {
                        regional = "官服";
                    }
                }

                JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(datum));
                if (Objects.equals(regional, data.getString("gameSystemName"))) {
                    resultMap.put("gameSystemId", data.getString("gameSystemId"));
                    resultMap.put("gameAreaId", data.getString("gameId"));
                    return resultMap;
                }
            }
        }
        return null;
    }

    private String coverGameId(String type) {

        if (Objects.equals(GameTypeConstant.WZRY, type)) {
            return "105";
        }
        if (Objects.equals(GameTypeConstant.HPJY, type)) {
            return "106";
        }
        if (Objects.equals(GameTypeConstant.YS, type)) {
            return "114";
        }
        if (Objects.equals(GameTypeConstant.LOL, type)) {
            return "107";
        }
        if (Objects.equals("枪战王者", type)) {
            return "108";
        }
        if (Objects.equals(GameTypeConstant.DNF, type)) {
            return "109";
        }
        if (Objects.equals("穿越火线", type)) {
            return "110";
        }
        if (Objects.equals(GameTypeConstant.YJWJ, type)) {
            return "115";
        }
        if (Objects.equals(GameTypeConstant.QQCAR, type)) {
            return "117";
        }
        if (Objects.equals(GameTypeConstant.HYRZ, type)) {
            return "116";
        }
        if (Objects.equals(GameTypeConstant.DNFF, type)) {
            return "109";
        }
        return null;
    }

    private String autonymStateCover(String level) {
        if (Objects.equals("有修改机会且实名是本人", level)) {
            return "2";
        } else if (Objects.equals("无修改机会且实名是本人", level)) {
            return "4";
        } else {
            return null;
        }
    }

    public static void main(String[] args) {
        Map<String, String> params = new HashMap<>();
        params.put("sign", "78a10c1238a64371bf003518cd080a8d");
        params.put("gameId", "116");
        String result = HttpUtils.doPostForm(OutUrlConstant.CRURLR, params, null);
        log.info(result);
    }

    static String getArea(SalePartner salePartner, String gameId) {
        Map<String, String> params = new HashMap<>();
        params.put("sign", salePartner.getSaleKey());
        params.put("gameId", gameId);
        String result = HttpUtils.doPostForm(OutUrlConstant.CRURLR, params, null);
        return result;
    }

}
